#include<thread>
#include<mutex>
#include<iostream>
#include<ctime>
using namespace std;

void Add1(int* px, int n, mutex* pmt)
{
	(*pmt).lock();
	for (int i = 0; i < n; i++)
	{
		(*px)++;
	}
	(*pmt).unlock();
}

void Fun1() {
	int x = 0;
	cout << "Before Add:x=" << x << endl;
	mutex mt;
	thread t1(Add1, &x, 10000000, &mt);
	thread t2(Add1, &x, 10000000, &mt);
	t1.join();
	t2.join();
	cout << "After Add:x=" << x << endl;
}

int main()
{
	int start1 = clock();
	Fun1();
	int end1 = clock();
	cout << "Fun1 Time Spend:" << end1 - start1 << endl;

	return 0;
}

